\documentclass[12pt,a4paper]{article}
\usepackage{hyperref}
\title{Overview of Changes in ++Paint}
\author{Anton Golov (3809277) and Roel van den Broek (3862577)}
\begin{document}
	\maketitle{}
		In the last three weeks we have been expanding and partially rewritting
		the program Schets in order to implement support for single-click
		deletion of objects, drawing of ellipses, saving the image as a bitmap,
		and saving the image as structured data.

		There were a number of design decisions to be made on the matter,
		primarily concerning the structure of the elements of a drawing.  Other
		than that, some expansion of the capabilities of tools was required,
		and the graphical user interface needed to be revamped to accomodate
		for the changes.

		Apart from that, we have also translated the program to English in
		order to reach a wider audience, and renamed it ++Paint to accomodate
		to the new users.

		\section{Code Organisation}
			The original code of Schets did not keep track of objects that have
			already been drawn.  Single-click deletion was not possible to
			implement without the addition of such a system.  For this purpose,
			two class hierarchies were created, with the interfaces
			\texttt{ILayer} and \texttt{IVisualObject}.

			The purpose of the \texttt{ILayer} hierarchy is to allow for easier
			management of objects, including the combination of multiple
			objects into one, and a limitation on what tools may do with the
			layer they are given.

			A single image in ++Paint is stored by a \texttt{LayerManager}.
			This is a class that keeps an ordered collection of layers, and
			raises events when the layers have been updated to a sufficient
			degree that they must be redrawn.

			Every image on the screen is represented by a
			\texttt{VisualObjectLayer} that contains a \texttt{IVisualObject}.
			These layers may be grouped in \texttt{CompositeLayers}, which may
			be grouped further as desired.

			A class derived from \texttt{IVisualObject} must be responsible for
			accepting certain manipulations with a tool, as well as for drawing
			itself on demand and reporting whether a certain point is within
			its hitbox.

			The third important hierarchy is that based on
			\texttt{ISketchTool}.  A tool must be capable of explaining to the
			\texttt{LayerManager} what kind of layer it wishes to work on, and
			is then given a layer if a suitable one is found.  The tools
			hierarchy is fairly deep in order to avoid duplicating
			functionality.

			The original tool hierarchy used by Schets proved somewhat too
			limited, which resulted in a fairly major rewrite.  This allowed
			for tools to be more aware of what layer they were acting on, and
			allowed for fewer methods that were only required by one or two
			visual objects.

			In order to implement reading and writing of images as layered
			data, several classes were created.  Amongst these was another
			hierarchy, with the interface \texttt{INode} as root.  This is a
			hierarchy used for the representation of a layered data file while
			it is being parsed, and is of little further interest.

		\section{Introduction to the New User Interface}
			The graphical user interface has been somewhat revamped.  It is now
			possible to select the colour by clicking on the coloured boxes at
			the bottom of the screen.  Double clicking allows a custom colour
			to be selected.

			The brush size can be changed by adjusting the slider to the left
			of the colours.

			The tools are, as they were, on the left of the screen.  They are,
			from top to bottom, the brush tool, the object deletion tool, the
			text addition tool, the line tool, the filled rectangle tool, the
			empty rectangle tool, the filled ellipse tool, and the empty
			ellipse tool.

			The main addition is the list of layers on the right.  The buttons
			under the layers, going from right to left, can be used to add,
			remove, move up, move down, group, and ungroup layers.  More than
			one layer can be selected by holding down the ctrl key.

			The menu has mostly remained unchanged, except for the ability to
			save and load files.

		\section{Format of the Layered Data}
			The format used to store layered data is a context-free language
			based on S-expressions.  The non-terminal symbols are
			\begin{description}
				\item[Start] is the initial non-terminal on the stack, and thus
				the entire data.
				\item[Node] is a single node in the output.
				\item[ArgumentList] is a list with the contents of the node.
				\item[ArgumentBundle] is either a single argument, or a label
				followed by the argument to be associated with it.
				\item[ArgumentLabel] is a label for a single argument.  It is
				an unquoted string consisting of upper- and lowercase letters
				and underscores.
				\item[Argument] is a single argument, that is either an
				integer, a quoted string, or a node.
				\item[NodeLabel] is a label denoting the type of a node.  The
				same restrictions apply as for an \textbf{ArgumentLabel}.
			\end{description}

			The terminal symbols are 
			\begin{description}
				\item[Integer] is a number, optionally with a sign (`$+$' or
				`$-$'), in base 10 (no prefix) or base 16 (`\texttt{0x}'
				prefix).
				\item[String] is a string between quotation marks
				(``\texttt{"}'').  A quotation mark within the string must be
				preceded by a backslash, and the letter \texttt{n}, preceded by
				a backslash, is treated as a new line.\footnote{The regular
				expressions used to match strings were taken from
				\url{http://wordaligned.org/articles/string-literals-and-regular-expressions}.}
				\item[Label] is an identifier that indicates the type of an
				object, or the name of an argument.  Labels must contain only
				upper- and lowercase letters and underscores.
			\end{description}

			Apart from these three terminals, there are certain terminals that
			aid with the layout but do not play much of a role otherwise;
			these are left unnamed, and defined in the rules by surrounding
			them with quotes.

			Note that all whitespace is ignored, except inside strings, where
			it is read literally and stored in the string.  The rules therefore
			mention no whitespace.  In some cases, it may be none the less
			necessary to use it for the separation of labels.

			The following are the rules of the grammar, with \textbf{Empty} being
			an	empty string.

			\begin{verbatim}
				Start -> "<<<" Node ">>>"
				Node -> "(" NodeLabel ArgumentList ")"
				ArgumentList -> ArgumentBundle ArgumentList
				ArgumentList -> Empty
				ArgumentBundle -> ArgumentLabel ":" Argument
				ArgumentBundle -> Argument
				Argument -> Node
				Argument -> String
				Argument -> Integer
				NodeLabel -> Label
				ArgumentLabel -> Label
			\end{verbatim}

			The \texttt{LayeredDataLexer} is responsible for splitting up the
			input into the tokens described and then returning them to the
			parser (\texttt{LayeredDataParser}) on demand.  The parser, which
			is LL(1), builds up an abstract syntax tree from members of the
			\texttt{INode} hierarchy.

			Once the abstract syntax tree is built, it is converted to a tree
			of \texttt{SerializedObject}s, which can then be deserialized into
			\texttt{ILayer}s and \texttt{IVisualObject}s as necessary.  Each
			member of those hierarchies is capable of translating itself to and
			from a \texttt{SerializedObject}.

			An example of a saved file is
			\begin{verbatim}
				<<<
				  (LayerManager
				    (VisualObjectLayer
				      (EmptyRectangle
				        100
				        100
				        50
				        50
				        colour:
				          -16777216
				      )
				    )
				  )
				>>>
			\end{verbatim}

			This defines an image with a single object, which is a not-filled
			rectangle that starts at position $(100, 100)$, is 50x50 pixels in
			size, and is black.

			Notice that the saved file has no concept of image size -- if the
			window is of an incorrect size upon loading, it will be displayed
			in a cropped manner, or with a white background, but with no loss
			of information.

		\section{Overview of Changes to the Source Code}
			The following is a summary of all changes to all functions.
			\begin{itemize}
				\item All identifiers and strings have been translated to
				English.
				\item The code has been placed into several namespaces.
				\item The colour choice options have been changed to allow for
				the user to set his own colours.
				\item The SketchControl is now responsible for reacting to user
				users interacting with the canvas.  
				\item The tools hierarchy has been fully rewritten to make use
				of the layers.
				\item Tools still draw the image that will appear when they
				are applied, but this is now done on a preview image.
				\item Every tool is usable for one drawing, and is then
				automatically scrapped and a new one is created.
				\item The Sketch class has been removed, in favour of every
				layer being responsible for drawing itself.
			\end{itemize}

		\section{Other comments}
			The rotate feature and the old eraser have been removed.

			The algorithms for finding the distance from a point to a line and
			for checking whether a point was inside an ellipse were written
			with our knowledge of linear algebra (TWINFO for the win).

			In case you're wondering why we wrote a parser instead of just
			using .Net serialization -- well, because it's of fun.
\end{document}
